<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" >

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" integrity="sha256-iM4Yzi/zLj/IshPWMC1IluRxTtRjMqjPGd97TZ9yYpU=" crossorigin="anonymous"></script>
  <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Cousine|Inconsolata" rel="stylesheet">
  <link rel="shortcut icon" type="image/png" href="/favicon.png">

  <link rel="stylesheet" href="/css/style.css">
  <link rel="stylesheet" href="/css/css/fontawesome-all.min.css">
  <link rel="stylesheet" href="/css/css/work-sans-v7.css">
  <script src="/js/main.js"></script>

  <!-- Begin Jekyll SEO tag v2.6.1 -->
<title>PY: Transfer Steem And Sbd To Savings Balance | Hive Developer</title>
<meta name="generator" content="Jekyll v4.0.0" />
<meta property="og:title" content="PY: Transfer Steem And Sbd To Savings Balance" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="How to transfer STEEM and SBD to savings using Python." />
<meta property="og:description" content="How to transfer STEEM and SBD to savings using Python." />
<link rel="canonical" href="transfer_steem_and_sbd_to_savings_balance.html" />
<meta property="og:url" content="transfer_steem_and_sbd_to_savings_balance.html" />
<meta property="og:site_name" content="Hive Developer" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2020-08-26T11:52:22-07:00" />
<script type="application/ld+json">
{"description":"How to transfer STEEM and SBD to savings using Python.","mainEntityOfPage":{"@type":"WebPage","@id":"transfer_steem_and_sbd_to_savings_balance.html"},"@type":"BlogPosting","url":"transfer_steem_and_sbd_to_savings_balance.html","headline":"PY: Transfer Steem And Sbd To Savings Balance","dateModified":"2020-08-26T11:52:22-07:00","datePublished":"2020-08-26T11:52:22-07:00","@context":"https://schema.org"}</script>
<!-- End Jekyll SEO tag -->


  
</head>
<body>
<header>
  <h1>
    <button type="button" class="open-nav" id="open-nav"></button>
    <a href="/"  class="logo-link"><img src="/images/logotype_black.svg" height="40" alt="Hive Developer logo"></a>
  </h1>

  
  <form action="/search/" method="get">
    <input type="text" name="q" id="search-input" placeholder="Search">
    <input type="submit" value="Search" style="display: none;">
  </form>
  

  <div id="sidebar" class="sidebar">
	
	
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/">
		<h6 class="ctrl-nav-section title">Introduction</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/#introduction-welcome">Welcome to Hive</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/quickstart/">
		<h6 class="ctrl-nav-section title">Quickstart</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/quickstart/#quickstart-choose-library">Choose Library</a></li>
						
					
						
						<li><a href="/quickstart/#quickstart-hive-full-nodes">Hive Nodes</a></li>
						
					
						
						<li><a href="/quickstart/#quickstart-testnet">Hive Testnet</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/tutorials/">
		<h6 class="ctrl-nav-section title">Tutorials</h6>
		<ul class="cont-nav-section content">
			
				
					
						<li><a href="/tutorials/#tutorials-javascript">Javascript</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-python">Python</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-ruby">Ruby</a></li>
					
				
					
						<li><a href="/tutorials/#tutorials-recipes">Recipes</a></li>
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/services/">
		<h6 class="ctrl-nav-section title">Services</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/services/#services-hive-blog">hive.blog</a></li>
						
					
						
						<li><a href="/services/#services-hivesigner">HiveSigner</a></li>
						
					
						
						<li><a href="/services/#services-jussi">Jussi</a></li>
						
					
						
						<li><a href="/services/#services-imagehoster">ImageHoster</a></li>
						
					
						
						<li><a href="/services/#services-dhf">DHF</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/apidefinitions/">
		<h6 class="ctrl-nav-section title">Appbase API</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/apidefinitions/#apidefinitions-condenser-api">Condenser Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-bridge">Bridge</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-account-by-key-api">Account By Key Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-account-history-api">Account History Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-block-api">Block Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-database-api">Database Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-debug-node-api">Debug Node Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-follow-api">Follow Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-jsonrpc">Jsonrpc</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-market-history-api">Market History Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-network-broadcast-api">Network Broadcast Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-rc-api">Rc Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-reputation-api">Reputation Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-rewards-api">Rewards Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-tags-api">Tags Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-transaction-status-api">Transaction Status Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-witness-api">Witness Api</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-broadcast-ops">Broadcast Ops</a></li>
						
					
						
						<li><a href="/apidefinitions/#apidefinitions-broadcast-ops-communities">Broadcast Ops Communities</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/resources/">
		<h6 class="ctrl-nav-section title">Resources</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/resources/#resources-overview">Overview</a></li>
						
					
						
						<li><a href="/resources/#resources-client-libs">Client Libraries</a></li>
						
					
						
						<li><a href="/resources/#resources-bluepaper">Bluepaper</a></li>
						
					
						
						<li><a href="/resources/#resources-whitepaper">Whitepaper</a></li>
						
					
						
						<li><a href="/resources/#resources-tools">Tools</a></li>
						
					
						
						<li><a href="/resources/#resources-hivesigner-libs">Hivesigner Libs</a></li>
						
					
						
						<li><a href="/resources/#resources-hive-keychain">Hive Keychain</a></li>
						
					
						
						<li><a href="/resources/#resources-developeradvocate">Community & Help</a></li>
						
					
				
			
		</ul>
	</section>
	
		
    <section class="pnl-main-nav-section main-nav-section" url="/glossary/">
		<h6 class="ctrl-nav-section title">Glossary</h6>
		<ul class="cont-nav-section content">
			
				
					
					
						
						<li><a href="/glossary/#glossary-chain-basics">Chain Basics</a></li>
						
					
						
					
						
						<li><a href="/glossary/#glossary-governance">Governance</a></li>
						
					
						
						<li><a href="/glossary/#glossary-transactions">Transactions</a></li>
						
					
						
						<li><a href="/glossary/#glossary-api">API</a></li>
						
					
						
						<li><a href="/glossary/#glossary-market">Market</a></li>
						
					
				
			
		</ul>
	</section>
	
</div>



  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
</header>
<div class="main" id="top">
  <div class="hero">
    <h1 class="hero__h1">Hive Developer Portal </h1>
    <img class="hero__img" src="/images/honey-comb-92.png" style="position: relative; top: 10px;" />
  </div>
  <section id="tutorials-python-transfer-steem-and-sbd-to-savings-balance" class="row tutorials-python-transfer-steem-and-sbd-to-savings-balance">
	<h3>
		<a id="tutorials-python-transfer-steem-and-sbd-to-savings-balance">
			PY: Transfer Steem And Sbd To Savings Balance
			
		</a>
	</h3>
	
		<span class="description"><p>How to transfer STEEM and SBD to savings using Python.</p>
</span>
	

	<p><span class="fa-pull-left top-of-tutorial-repo-link"><span class="first-word">Full</span>, runnable src of <a href="https://gitlab.syncad.com/hive/devportal/-/tree/master/tutorials/python/tutorials/33_transfer_steem_and_sbd_to_savings_balance">Transfer Steem And Sbd To Savings Balance</a> can be downloaded as part of: <a href="https://gitlab.syncad.com/hive/devportal/-/tree/master/tutorials/python">tutorials/python</a>.</span>
<br /></p>

<p>In this tutorial we show you how to check the STEEM and SBD balance of an account on the <strong>Steem</strong> blockchain and also how to transfer a portion or all of that to a “savings” account using the <code class="highlighter-rouge">commit</code> class found within the <a href="https://github.com/steemit/steem-python">steem-python</a> library.</p>

<p>It should be noted that when funds are being withdrawn from the savings account it takes 3 days for those funds to reflect in the available STEEM/SBD balance. The withdrawal can be cancelled at any point during this waiting period. This measure was put in place to reduce the risk of funds being stolen when accounts are hacked as it gives sufficient time to recover your account before your funds are transferred out. Storing your funds in your savings account is thus more secure than having them as available balances.</p>

<p>Steemconnect offers an alternative to transferring STEEM and SBD with a “simple link” solution. Instead of running through a list of operations on your account, you can simply use a link similar to the one below substituting the four parameters with your own details. You will be prompted to enter your username and password before the transaction will be executed.
https://steemconnect.com/sign/transfer-to-savings?from=username&amp;to=username&amp;amount=0.000%20STEEM&amp;memo=text
This is similar to the steemconnect links that have been covered in previous tutorials. For a list of signing operations that work in this manner you can go to https://v2.steemconnect.com/sign. There is also a steemconnect link for withdrawing funds.</p>

<h2 id="intro">Intro</h2>

<p>The Steem python library has a built-in function to transmit transactions to the blockchain. We are using the <code class="highlighter-rouge">transfer_to_savings</code> and <code class="highlighter-rouge">transfer_from_savings</code> methods found within the <code class="highlighter-rouge">commit</code> class in the library. Before we do the transfer, we use the <code class="highlighter-rouge">get_account</code> function to check the current STEEM and SBD balance of the account to see what funds are available to transfer or withdraw. This is not strictly necessary but adds to the useability of the process. The <code class="highlighter-rouge">transfer_to_savings</code> method has 5 parameters:</p>

<ol>
  <li><em>amount</em> - The amount of STEEM or SBD that the user wants to transfer. This parameter has to be of the <code class="highlighter-rouge">float</code> data type and is rounded up to 3 decimal spaces</li>
  <li><em>asset</em> - A string value specifying whether <code class="highlighter-rouge">STEEM</code> or <code class="highlighter-rouge">SBD</code> is being transferred</li>
  <li><em>memo</em> - An optional text field containing comments on the transfer</li>
  <li><em>to</em> - The recipient savings account name. Funds can be transferred to any other users’ savings balance</li>
  <li><em>account</em> - The source account for the transfer</li>
</ol>

<p>and <code class="highlighter-rouge">transfer_from_savings</code> has 6 parameters:</p>

<ol>
  <li><em>amount</em> - The amount of STEEM or SBD that the user wants to withdraw. This parameter has to be of the <code class="highlighter-rouge">float</code> data type and is rounded up to 3 decimal spaces</li>
  <li><em>asset</em> - A string value specifying whether <code class="highlighter-rouge">STEEM</code> or <code class="highlighter-rouge">SBD</code> is being withdrawn</li>
  <li><em>memo</em> - An optional text field containing comments on the withdrawal</li>
  <li><em>request id</em> - Integer identifier for tracking the withdrawal. This needs to be a unique number for a specified user</li>
  <li><em>to</em> - The recipient account name. Funds can be withdrawn to any other users’ available balance</li>
  <li><em>account</em> - The source account for the transfer</li>
</ol>

<h2 id="steps">Steps</h2>

<ol>
  <li><a href="#setup"><strong>App setup</strong></a> - Library install and import. Connection to testnet</li>
  <li><a href="#userinfo"><strong>User information and steem node</strong></a> - Input user information and connection to Steem node</li>
  <li><a href="#balance"><strong>Check balance</strong></a> - Check current STEEM and SBD balance of user account</li>
  <li><a href="#amount"><strong>Transfer type and amount</strong></a> - Input of transfer type and the amount to transfer</li>
  <li><a href="#commit"><strong>Transfer commit</strong></a> - Commit of transfer to blockchain</li>
</ol>

<h4 id="1-app-setup-">1. App setup <a name="setup"></a></h4>

<p>In this tutorial we use 3 packages:</p>

<ul>
  <li><code class="highlighter-rouge">steem</code> - steem-python library and interaction with Blockchain</li>
  <li><code class="highlighter-rouge">pick</code> - helps select the query type interactively</li>
  <li><code class="highlighter-rouge">random</code> - use to create random numbers</li>
</ul>

<p>We import the libraries and connect to the <code class="highlighter-rouge">testnet</code>.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">steembase</span>
<span class="kn">import</span> <span class="nn">steem</span>
<span class="kn">from</span> <span class="nn">pick</span> <span class="kn">import</span> <span class="n">pick</span>
<span class="kn">import</span> <span class="nn">random</span>

<span class="n">steembase</span><span class="o">.</span><span class="n">chains</span><span class="o">.</span><span class="n">known_chains</span><span class="p">[</span><span class="s">'STEEM'</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">'chain_id'</span><span class="p">:</span> <span class="s">'79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673'</span><span class="p">,</span>
    <span class="s">'prefix'</span><span class="p">:</span> <span class="s">'STX'</span><span class="p">,</span> <span class="s">'steem_symbol'</span><span class="p">:</span> <span class="s">'STEEM'</span><span class="p">,</span> <span class="s">'sbd_symbol'</span><span class="p">:</span> <span class="s">'SBD'</span><span class="p">,</span> <span class="s">'vests_symbol'</span><span class="p">:</span> <span class="s">'VESTS'</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Because this tutorial alters the blockchain we connect to a testnet so we don’t create spam on the production server.</p>

<h4 id="2-user-information-and-steem-node-">2. User information and steem node <a name="userinfo"></a></h4>

<p>We require the <code class="highlighter-rouge">private active key</code> of the user in order for the transfer to be committed to the blockchain. This is why we are using a testnet. The values are supplied via the terminal/console before we initialise the steem class. There are some demo accounts available but we encourage you to create your own accounts on a testnet and create balances you can transfer; it’s good practice.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#capture user information
</span><span class="n">username</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Enter username: '</span><span class="p">)</span> <span class="c1">#demo account: demo01
</span><span class="n">wif</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Enter private ACTIVE key: '</span><span class="p">)</span> <span class="c1">#demo account: 5HxTntgeoLm4trnTz94YBsY6MpAap1qRVXEKsU5n1v2du1gAgVH
</span>
<span class="c1">#connect node and private active key
</span><span class="n">client</span> <span class="o">=</span> <span class="n">steem</span><span class="o">.</span><span class="n">Steem</span><span class="p">(</span><span class="n">nodes</span><span class="o">=</span><span class="p">[</span><span class="s">'https://testnet.steem.vc'</span><span class="p">],</span> <span class="n">keys</span><span class="o">=</span><span class="p">[</span><span class="n">wif</span><span class="p">])</span>
</code></pre></div></div>

<h4 id="3-check-balance-">3. Check balance <a name="balance"></a></h4>

<p>In order to give the user enough information to make the transfer we check the current balance of both the available and savings funds of the account using the <code class="highlighter-rouge">get_account</code> function.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#check for valid account and get account balance for STEEM and SBD
</span><span class="n">userinfo</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_account</span><span class="p">(</span><span class="n">username</span><span class="p">)</span>
<span class="k">if</span><span class="p">(</span><span class="n">userinfo</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">)</span> <span class="p">:</span>
    <span class="k">print</span><span class="p">(</span><span class="s">'Oops. Looks like user '</span> <span class="o">+</span> <span class="n">username</span> <span class="o">+</span> <span class="s">' doesn</span><span class="se">\'</span><span class="s">t exist on this chain!'</span><span class="p">)</span>
    <span class="nb">exit</span><span class="p">()</span>

<span class="n">total_steem</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'balance'</span><span class="p">]</span>
<span class="n">total_sbd</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'sbd_balance'</span><span class="p">]</span>
<span class="n">savings_steem</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'savings_balance'</span><span class="p">]</span>
<span class="n">savings_sbd</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'savings_sbd_balance'</span><span class="p">]</span>

<span class="k">print</span><span class="p">(</span><span class="s">'CURRENT ACCOUNT BALANCE:'</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">total_steem</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">total_sbd</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'CURRENT SAVINGS BALANCE:'</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">savings_steem</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">savings_sbd</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="p">)</span>

<span class="nb">input</span><span class="p">(</span><span class="s">'Press enter to continue with the transfer'</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="p">)</span>
</code></pre></div></div>

<p>The result of the query is displayed in the console/terminal.</p>

<h4 id="4-transfer-type-and-amount-">4. Transfer type and amount <a name="amount"></a></h4>

<p>The user is given a choice on the type of transfer (transfer/withdraw) as well as the currency. The user can also elect to cancel the process entirely. If you are using one of Steemit’s demo accounts, please leave some funds for others to transfer! Once the user makes their choice we proceed to assign the <code class="highlighter-rouge">amount</code> as well as the <code class="highlighter-rouge">asset</code> parameter.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#choice of transfer/withdrawal
</span><span class="n">title1</span> <span class="o">=</span> <span class="s">'Please choose transfer type: '</span>
<span class="n">options1</span> <span class="o">=</span> <span class="p">[</span><span class="s">'Transfer'</span><span class="p">,</span> <span class="s">'Withdrawal'</span><span class="p">,</span> <span class="s">'Cancel'</span><span class="p">]</span>
<span class="c1">#get index and selected transfer type
</span><span class="n">transfer_type</span><span class="p">,</span> <span class="n">index</span> <span class="o">=</span> <span class="n">pick</span><span class="p">(</span><span class="n">options1</span><span class="p">,</span> <span class="n">title1</span><span class="p">)</span>

<span class="k">if</span> <span class="n">transfer_type</span> <span class="o">==</span> <span class="s">'Cancel'</span><span class="p">:</span>
    <span class="k">print</span><span class="p">(</span><span class="s">'Transaction cancelled'</span><span class="p">)</span>
    <span class="nb">exit</span><span class="p">()</span>

<span class="c1">#choice of currency
</span><span class="n">title2</span> <span class="o">=</span> <span class="s">'Please choose currency: '</span>
<span class="n">options2</span> <span class="o">=</span> <span class="p">[</span><span class="s">'STEEM'</span><span class="p">,</span> <span class="s">'SBD'</span><span class="p">]</span>
<span class="n">option</span><span class="p">,</span> <span class="n">index</span> <span class="o">=</span> <span class="n">pick</span><span class="p">(</span><span class="n">options2</span><span class="p">,</span> <span class="n">title2</span><span class="p">)</span>

<span class="k">if</span> <span class="n">option</span> <span class="o">==</span> <span class="s">'STEEM'</span><span class="p">:</span>
    <span class="c1">#get STEEM transfer amount
</span>    <span class="n">amount</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Enter amount of STEEM to transfer: '</span><span class="p">)</span>
    <span class="n">asset</span> <span class="o">=</span> <span class="s">'STEEM'</span>
<span class="k">else</span><span class="p">:</span>
    <span class="c1">#get SBD transfer amount
</span>    <span class="n">amount</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s">'Enter amount of SBD to transfer: '</span><span class="p">)</span>
    <span class="n">asset</span> <span class="o">=</span> <span class="s">'SBD'</span>
</code></pre></div></div>

<h4 id="5-transfer-commit-">5. Transfer commit <a name="commit"></a></h4>

<p>Once all the parameters have been assigned we can proceed with the actual commit to the blockchain. The relevant function is executed based on the selected choice the user made in the previous step.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">if</span> <span class="n">transfer_type</span> <span class="o">==</span> <span class="s">'Transfer'</span><span class="p">:</span>
    <span class="c1">#parameters: amount, asset, memo, to, account
</span>    <span class="n">client</span><span class="o">.</span><span class="n">transfer_to_savings</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">amount</span><span class="p">),</span> <span class="n">asset</span><span class="p">,</span> <span class="s">''</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">username</span><span class="p">)</span>
    <span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="s">'Transfer to savings balance successful'</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
    <span class="c1">#create request ID random integer
</span>    <span class="n">requestID</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1000000</span><span class="p">)</span>
    <span class="c1">#parameters: amount, asset, memo, request_id=None, to=None, account=None
</span>    <span class="n">client</span><span class="o">.</span><span class="n">transfer_from_savings</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">amount</span><span class="p">),</span> <span class="n">asset</span><span class="p">,</span> <span class="s">''</span><span class="p">,</span> <span class="n">requestID</span><span class="p">,</span> <span class="n">username</span><span class="p">,</span> <span class="n">username</span><span class="p">)</span>
    <span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="s">'Withdrawal from savings successful, transaction ID: '</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">requestID</span><span class="p">))</span>
</code></pre></div></div>

<p>With a withdrawal, the method requires a unique identifier for the transaction to be completed. For this we create a random integer and also display it on the UI along with the result of the transaction. The <code class="highlighter-rouge">memo</code> parameter is optional and can be left empty as in the above example. We also use the source account for the <code class="highlighter-rouge">to</code> parameter. This can be replace by any other valid user account. A simple confirmation of the transfer is printed on the UI.</p>

<p>As an added confirmation we check the balance of the user again and display it on the UI. This is not required at all but it serves as a more definitive confirmation that the transfer has been completed correctly.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">#get remaining account balance for STEEM and SBD
</span><span class="n">userinfo</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_account</span><span class="p">(</span><span class="n">username</span><span class="p">)</span>
<span class="n">total_steem</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'balance'</span><span class="p">]</span>
<span class="n">total_sbd</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'sbd_balance'</span><span class="p">]</span>
<span class="n">savings_steem</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'savings_balance'</span><span class="p">]</span>
<span class="n">savings_sbd</span> <span class="o">=</span> <span class="n">userinfo</span><span class="p">[</span><span class="s">'savings_sbd_balance'</span><span class="p">]</span>

<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="s">'REMAINING ACCOUNT BALANCE:'</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">total_steem</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">total_sbd</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="s">'CURRENT SAVINGS BALANCE:'</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">savings_steem</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span> <span class="o">+</span> <span class="n">savings_sbd</span> <span class="o">+</span> <span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="p">)</span>
</code></pre></div></div>

<p>We encourage users to play around with different values and data types to fully understand how this process works. You can also check the balances and transaction history on the <a href="http://condenser.steem.vc/">testnet portal</a>.</p>

<h3 id="to-run-the-tutorial">To Run the tutorial</h3>

<ol>
  <li><a href="getting_started.html">review dev requirements</a></li>
  <li><code class="highlighter-rouge">git clone https://gitlab.syncad.com/hive/devportal.git</code></li>
  <li><code class="highlighter-rouge">cd devportal/tutorials/python/33_transfer_steem_and_sbd_to_savings_balance</code></li>
  <li><code class="highlighter-rouge">pip install -r requirements.txt</code></li>
  <li><code class="highlighter-rouge">python index.py</code></li>
  <li>After a few moments, you should see a prompt for input in terminal screen.</li>
</ol>

<hr />

</section>

</div>
<div class="footer">
  <a href="#">Back to top</a>
</div>
<script>
    document.getElementById("open-nav").addEventListener("click", function () {
        document.body.classList.toggle("nav-open");
    });
</script>
</body>
</html>


<script src="/js/adjust.js"></script>

